package org.footballmanager.pandafootball.system.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.common.util.RandomNumber;
import org.footballmanager.pandafootball.common.util.StringUtil;
import org.footballmanager.pandafootball.system.domain.*;
import org.footballmanager.pandafootball.system.form.impl.FootPersonSearchForm;
import org.footballmanager.pandafootball.system.mapper.FootUserPersonMapper;
import org.footballmanager.pandafootball.system.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.util.*;

@Slf4j
@Service
public class FootUserPersonServiceImpl extends ServiceImpl<FootUserPerson> implements FootUserPersonService {
    private static final String SORT = "num";
    @Autowired
    private FootUserPersonMapper footUserPersonMapper;
    @Autowired
    private FootPersonService footPersonService;
    @Autowired
    private FootTeamService footTeamService;
    @Autowired
    private FootUserService footUserService;
    @Autowired
    private FootZnxService footZnxService;
    @Autowired
    private FootSjService footSjService;
    @Autowired
    private FootBfDetailService footBfDetailService;
    @Autowired
    private FootBfMvpService footBfMvpService;

    /**
     * 下放指定用户的指定球员
     *
     * @param userId  用户主键
     * @param qyId    球员主键
     * @param xycs    续约次数
     * @param request 请求
     */
    @Override
    @Transactional
    public void deletePersonFromMyTeam(Long userId, Long qyId, Integer xycs, HttpServletRequest request) {
        FootUserPerson fup = this.findPersonByQyidandXycs(userId, qyId, xycs);
        if (null != fup) {
            this.delete(fup.getId(), request);
        }
        List<FootUserPerson> list = this.findFootPersonsByUserIdandQyId(userId, qyId);
        if (list != null && !list.isEmpty()) {
            for (FootUserPerson fuperson : list) {
                fuperson.setNum(fuperson.getNum() - 1);
                this.updateNotNull(fuperson, request);
            }
        }
    }

    /**
     * 下放指定用户的所有球员
     *
     * @param userId  用户主键
     * @param request 请求
     */
    @Override
    @Transactional
    public void deleteAllPerson(Long userId, HttpServletRequest request) {
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(Constants.USERID, userId);
        criteria.andEqualTo("delFlag", 0);
        List<FootUserPerson> list = this.findall(example);
        if (list != null && !list.isEmpty()) {
            for (FootUserPerson fup : list) {
                this.delete(fup.getId(), request);
            }
        }
    }

    /**
     * 随机分配11个75分以下的球员
     *
     * @param userId  用户主键
     * @param request 请求
     */
    @Override
    @Transactional
    public void randomLow75(Long userId, HttpServletRequest request) {
        Random r = new Random();
        FootPersonSearchForm footPersonSearchForm = new FootPersonSearchForm();
        processWhiteMan(footPersonSearchForm, r, userId, request);
        processGreenMan(footPersonSearchForm, r, userId, request);
        processBlueMan(footPersonSearchForm, r, userId, request);
        processPurpleMan(footPersonSearchForm, r, userId, request);
    }

    /**
     * 根据条件处理大众白人
     *
     * @param footPersonSearchForm 条件
     * @param r                    随机数
     * @param userId               用户主键
     * @param request              请求
     */
    private void processWhiteMan(FootPersonSearchForm footPersonSearchForm, Random r, Long userId, HttpServletRequest request) {
        footPersonSearchForm.setDjId(1L);
        List<FootPerson> list = footPersonService.findall(footPersonSearchForm);
        if (list == null || list.isEmpty()) {
            return;
        }
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        Set<Integer> set3 = new HashSet<>();
        Set<Integer> set4 = new HashSet<>();
        while (true) {
            Integer g = r.nextInt(list.size() - 1);
            processWz(g, list, set1, set2, set3, set4);

            if ((set1.size() == 1 && set2.size() == 2) && (set3.size() == 4 && set4.size() == 4)) {
                break;
            }
        }
        set1.addAll(set2);
        set1.addAll(set3);
        set1.addAll(set4);
        for (Integer h : set1) {
            FootPerson fp = list.get(h);
            this.saveUserPerson(userId, fp, request);
        }
    }

    /**
     * 处理位置信息
     *
     * @param i    第i位
     * @param list 球员列表
     * @param set1 集合1
     * @param set2 集合2
     * @param set3 集合3
     * @param set4 集合4
     */
    private void processWz(Integer i, List<FootPerson> list, Set<Integer> set1, Set<Integer> set2, Set<Integer> set3, Set<Integer> set4) {
        FootPerson fp = list.get(i);
        boolean flag1 = "DMF".equals(fp.getWzbm()) || "AMF".equals(fp.getWzbm());
        boolean flag2 = "LMF".equals(fp.getWzbm()) || "RMF".equals(fp.getWzbm());
        boolean flag3 = "CF".equals(fp.getWzbm()) || "SS".equals(fp.getWzbm());
        boolean flag4 = "LWF".equals(fp.getWzbm()) || "RWF".equals(fp.getWzbm());
        if ("GK".equals(fp.getWzbm()) && set1.isEmpty()) {
            set1.add(i);
        } else if (("CB".equals(fp.getWzbm()) || "LB".equals(fp.getWzbm()) ||
                "RB".equals(fp.getWzbm())) && set3.size() < 4) {
            set3.add(i);
        } else if ((flag1 || flag2) && set4.size() < 4) {
            set4.add(i);
        } else if ((flag3 || flag4) && set2.size() < 2) {
            set2.add(i);
        }
    }

    /**
     * 根据条件处理普通球星
     *
     * @param footPersonSearchForm 条件
     * @param r                    随机数
     * @param userId               用户主键
     * @param request              请求
     */
    private void processGreenMan(FootPersonSearchForm footPersonSearchForm, Random r, Long userId, HttpServletRequest request) {
        footPersonSearchForm.setDjId(2L);
        List<FootPerson> listlv = footPersonService.findall(footPersonSearchForm);
        if (listlv != null && !listlv.isEmpty()) {
            Set<Integer> set = new HashSet<>();
            while (true) {
                set.add(r.nextInt(listlv.size() - 1));
                if (set.size() == 4) {
                    break;
                }
            }
            for (Integer i : set) {
                FootPerson fp = listlv.get(i);
                this.saveUserPerson(userId, fp, request);
            }
        }
    }

    /**
     * 根据条件处理洲际球星
     *
     * @param footPersonSearchForm 条件
     * @param r                    随机数
     * @param userId               用户主键
     * @param request              请求
     */
    private void processBlueMan(FootPersonSearchForm footPersonSearchForm, Random r, Long userId, HttpServletRequest request) {
        footPersonSearchForm.setDjId(2L);
        List<FootPerson> listlan = footPersonService.findall(footPersonSearchForm);
        if (listlan != null && !listlan.isEmpty()) {
            Set<Integer> set = new HashSet<>();
            while (true) {
                set.add(r.nextInt(listlan.size() - 1));
                if (set.size() == 2) {
                    break;
                }
            }
            for (Integer i : set) {
                FootPerson fp = listlan.get(i);
                this.saveUserPerson(userId, fp, request);
            }
        }
    }

    /**
     * 根据条件处理超级球星
     *
     * @param footPersonSearchForm 条件
     * @param r                    随机数
     * @param userId               用户主键
     * @param request              请求
     */
    private void processPurpleMan(FootPersonSearchForm footPersonSearchForm, Random r, Long userId, HttpServletRequest request) {
        footPersonSearchForm.setDjId(4L);
        List<FootPerson> listzi = footPersonService.findall(footPersonSearchForm);
        if (listzi != null && !listzi.isEmpty()) {
            FootPerson fp = listzi.get(r.nextInt(listzi.size() - 1));
            this.saveUserPerson(userId, fp, request);
        }
    }

    /**
     * 续约球员
     *
     * @param userId  用户主键
     * @param qyId    球员主键
     * @param xycs    数量
     * @param request 请求
     * @return josn返回值
     */
    @Override
    public JsonReturn renew(Long userId, Long qyId, Integer xycs, HttpServletRequest request) {
        FootUserPerson fup = this.findPersonByQyidandXycs(userId, qyId, xycs);
        if (null != fup) {
            FootTeam team = footTeamService.getTeamByUserid(userId);
            FootPerson fp = footPersonService.get(qyId);
            Double money = Double.valueOf(fp.getQysj()) * 0.5D;
            if (team != null) {
                if (money > team.getQdZzj()) {
                    return new JsonReturn("资金不够续约球员");
                }
                team.setQdZzj(team.getQdZzj() - money);
                team.setYy("因续约球员" + StringUtil.getFullNameFromPerson(fp) +
                        ",扣除:" + new DecimalFormat(",###").format(money) + "PB");
                footTeamService.updateNotNull(team, request);
                fup.setXycs(fup.getXycs() + 50);
                this.updateNotNull(fup, request);
                return new JsonReturn(Constants.OK);
            } else {
                return new JsonReturn("续约失败");
            }
        }
        return new JsonReturn("无此球员，可能已经被系统自动下放了");
    }

    /**
     * 根据用户主键查找该用户的所有信息
     *
     * @param userId 用户主键
     * @return 该用户的所有球员信息列表
     */
    @Override
    public List<FootUserPerson> findPersonByUserId(Long userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("sj", footSjService.getSj());
        return footUserPersonMapper.findByMap(map);
    }

    /**
     * 根据用户主键查找该用户的所有球员
     *
     * @param isQd    是否获取球队信息
     * @param userId  用户主键
     * @param request 请求  @return 该用户的所有球员列表
     */
    @Override
    public List<FootPerson> findFootPersonByUserId(Long userId, HttpServletRequest request) {
        if (StringUtils.isEmpty(userId)) {
            return Collections.emptyList();
        }
        List<FootPerson> list = new ArrayList<>();
        List<FootUserPerson> fuplist = this.findPersonByUserId(userId);
        if (fuplist == null || fuplist.isEmpty()) {
            return Collections.emptyList();
        }
        List<FootPerson> personList = new ArrayList<>();
        for (FootUserPerson fup : fuplist) {
            FootPerson fp = footPersonService.get(fup.getQyId());
            if (null != fp) {
                Long id = fp.getId();
                BeanUtils.copyProperties(fup, fp);
                fp.setFupId(fup.getId());
                fp.setId(id);
                personList.add(fp);
            } else {
                if (fup.getQyId() != null) {
                    this.delete(fup, request);
                }
            }
        }
        personList.sort(Comparator.comparing(FootPerson::getDjId));
        return personList;
    }

    /**
     * 自动减球员场次，如果为0自动解约
     *
     * @param userId  用户主键
     * @param request 请求
     */
    @Override
    public void autoDeletePerson(Long userId, HttpServletRequest request) {
        List<FootUserPerson> list = this.findPersonByUserId(userId);
        for (FootUserPerson fup : list) {
            fup.setXycs(fup.getXycs() - 1);
            this.updateNotNull(fup, request);
            if (fup.getXycs().equals(0)) {
                FootPerson fp = footPersonService.get(fup.getQyId());
                this.delete(fup.getId(), request);
                footZnxService.sendZnx(footUserService.getAdminUserid(), userId,
                        "由于球员" + StringUtil.getFullNameFromPerson(fp) +
                                "的续约次数已到,您没有及时续约,系统自动解约该球员", null, null, request);
            }
        }
    }

    /**
     * 增加次数，为删除报分使用
     *
     * @param userId  用户主键
     * @param request 请求
     */
    @Override
    public void addUseTimes(Long userId, HttpServletRequest request) {
        List<FootUserPerson> list = this.findPersonByUserId(userId);
        if (list != null && !list.isEmpty()) {
            for (FootUserPerson fup : list) {
                fup.setXycs(fup.getXycs() + 1);
                this.updateNotNull(fup, request);
            }
        }
    }

    /**
     * 保存球员到数据库中
     *
     * @param userId     用户主键
     * @param footPerson 球员实体类
     * @param request    请求
     */
    @Override
    public void saveUserPerson(Long userId, FootPerson footPerson, HttpServletRequest request) {
        FootUserPerson fup = new FootUserPerson();
        fup.setQyId(footPerson.getId());
        fup.setYw(footPerson.getYw());
        fup.setUserId(userId);
        fup.setXycs(50);
        fup.setPower((double) footPerson.getPf());
        fup.setMain(true);
        //获取球队人数
        List<FootUserPerson> list = this.findFootPersonsByUserIdandQyId(userId, footPerson.getId());
        fup.setNum(list.size() + 1);
        this.save(fup, request);
    }

    /**
     * 获取可以挂牌的所有球员
     *
     * @param userId 用户主键
     * @return 可以挂牌的所有球员列表
     */
    @Override
    public List<FootPerson> findCanGpPerson(Long userId) {
        List<FootPerson> list = new ArrayList<>();
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(Constants.USERID, userId);
        criteria.andEqualTo("delFlag", 0);
        List<FootUserPerson> fupList = this.findall(example);
        if (fupList != null && !fupList.isEmpty()) {
            for (FootUserPerson fup : fupList) {
                if (fup.getXycs() > 0) {
                    FootPerson fp = footPersonService.get(fup.getQyId());
                    fp.setFupId(fup.getId());
                    fp.setXycs(fup.getXycs());
                    list.add(fp);
                }
            }
        }
        return list;
    }

    /**
     * 根据用户主键和球员主键找球员关系信息列表
     *
     * @param userId 用户主键
     * @param qyId   球员主键
     * @return 球员关系信息列表
     */
    @Override
    public List<FootUserPerson> findFootPersonsByUserIdandQyId(Long userId, Long qyId) {
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != userId) {
            criteria.andEqualTo(Constants.USERID, userId);
        }
        criteria.andEqualTo("qyId", qyId);
        criteria.andEqualTo("delFlag", 0);
        example.orderBy(SORT).desc();
        return this.findall(example);
    }

    /**
     * 查看主力人员人数
     *
     * @param user 用户实体类
     * @return 人数
     */
    @Override
    public int checkMainPerson(FootUser user) {
        int result = 0;
        List<FootUserPerson> list = this.findPersonByUserId(user.getId());
        if (null != list && !list.isEmpty()) {
            for (FootUserPerson fup : list) {
                if (fup.getMain()) {
                    result += 1;
                }
            }
        }
        return result;
    }

    /**
     * 根据用户主键获取该用户的主力战斗值
     *
     * @param userId  用户主键
     * @param request 请求
     * @return 主力战斗值
     */
    @Override
    public double getPower(Long userId, HttpServletRequest request) {
        Double result = 0D;
        List<FootPerson> list = this.findFootPersonByUserId(userId, request);
        if (null != list && !list.isEmpty()) {
            for (FootPerson fp : list) {
                if (fp.getMain()) {
                    result += Double.valueOf(fp.getPf());
                }
            }
        }
        return result;
    }

    /**
     * 合成球员，增加战力
     *
     * @param fupId1  球员1关系主键
     * @param fupId2  球员2关系主键
     * @param request 请求
     * @return json返回值
     */
    @Override
    public JsonReturn compose(Long fupId1, Long fupId2, HttpServletRequest request) {
        /*
         * 	同样2名球员可以升级，升级后球员战力增长20%  同可升级5次
         *	1+1=2     		成功率100%
         *	2+1=3    		成功率90%
         *	3+1=4     2+2=4   成功率80%
         *	4+1=5     3+2=5   成功率70%
         *	升级失败 低级别球员消失  高级别球员不变
         *	升级成功 低级别球员消失  高级别球员升级
         */
        FootUserPerson fup1 = this.get(fupId1);
        FootUserPerson fup2 = this.get(fupId2);
        int result = RandomNumber.randomNumber();
        if (!fup1.getQyId().equals(fup2.getQyId())) {
            return new JsonReturn("合成球员必须为同一球员");
        }
        //看球员是否有等级差
        if (fup1.getPower() > fup2.getPower()) {
            return processGreaterThan(fup1, fup2, request, result);
        } else if (fup1.getPower().equals(fup2.getPower())) {
            return processEquals(fup1, fup2, request, result);
        } else {
            return processLessThan(fup1, fup2, request, result);
        }
    }

    /**
     * 处理数据
     *
     * @param fup1 关系1实体类
     * @param num1 数量1
     * @param fup2 关系2实体类
     * @param num2 数量2
     * @return 是否相等
     */
    private boolean processBoolean(FootUserPerson fup1, Integer num1, FootUserPerson fup2, Integer num2) {
        return fup1.getUpTimes().equals(num1) && fup2.getUpTimes().equals(num2);
    }

    /**
     * 处理不相等，小于一方
     *
     * @param fup1    关系1实体类
     * @param fup2    关系2实体类
     * @param request 请求
     * @param result  结果
     * @return json返回值
     */
    private JsonReturn processLessThan(FootUserPerson fup1, FootUserPerson fup2, HttpServletRequest request, int result) {
        boolean flag1 = processBoolean(fup1, 1, fup2, 2);
        boolean flag2 = processBoolean(fup1, 1, fup2, 3);
        boolean flag3 = processBoolean(fup1, 1, fup2, 4);
        boolean flag4 = processBoolean(fup1, 2, fup2, 3);
        return processFlag(flag1, flag2, flag3, flag4, fup1, fup2, request, result, false);
    }

    /**
     * 处理相等
     *
     * @param fup1    关系1实体类
     * @param fup2    关系2实体类
     * @param request 请求
     * @param result  结果
     * @return json返回值
     */
    private JsonReturn processEquals(FootUserPerson fup1, FootUserPerson fup2, HttpServletRequest request, int result) {
        if (processBoolean(fup1, 1, fup2, 1) && result <= 100) {
            return this.composeSuccess(fup1, fup2, request, true);
        } else if (processBoolean(fup1, 2, fup2, 2) && result <= 80) {
            return this.composeSuccess(fup1, fup2, request, true);
        }
        return this.composeFailed(fup2.getId(), request);
    }

    /**
     * 处理不相等，大于一方
     *
     * @param fup1    关系1实体类
     * @param fup2    关系2实体类
     * @param request 请求
     * @param result  结果
     * @return json返回值
     */
    private JsonReturn processGreaterThan(FootUserPerson fup1, FootUserPerson fup2, HttpServletRequest request, int result) {
        boolean flag1 = processBoolean(fup1, 2, fup2, 1);
        boolean flag2 = processBoolean(fup1, 3, fup2, 1);
        boolean flag3 = processBoolean(fup1, 4, fup2, 1);
        boolean flag4 = processBoolean(fup1, 3, fup2, 2);
        return processFlag(flag1, flag2, flag3, flag4, fup1, fup2, request, result, true);
    }

    /**
     * 处理flag
     *
     * @param flag1   标志1
     * @param flag2   标志2
     * @param flag3   标志3
     * @param flag4   标志4
     * @param fup1    关系1实体类
     * @param fup2    关系2实体类
     * @param request 请求
     * @param result  结果
     * @param isFup2  是否是关系2
     * @return json返回值
     */
    private JsonReturn processFlag(boolean flag1, boolean flag2, boolean flag3, boolean flag4, FootUserPerson fup1, FootUserPerson fup2,
                                   HttpServletRequest request, int result, boolean isFup2) {
        if (flag1 && result <= 90) {
            return this.composeSuccess(fup1, fup2, request, isFup2);
        } else if (flag2 && result <= 80) {
            return this.composeSuccess(fup1, fup2, request, isFup2);
        } else if ((flag3 || flag4) && result <= 70) {
            return this.composeSuccess(fup1, fup2, request, isFup2);
        }
        if (isFup2) {
            return this.composeFailed(fup2.getId(), request);
        } else {
            return this.composeFailed(fup1.getId(), request);
        }
    }

    /**
     * 合成成功
     *
     * @param fup1    关系1实体类
     * @param fup2    关系2实体类
     * @param request 请求
     * @param isFup2  是否是关系2
     * @return json返回值
     */
    private JsonReturn composeSuccess(FootUserPerson fup1, FootUserPerson fup2, HttpServletRequest request, boolean isFup2) {
        //合成成功
        if (isFup2) {
            fup1.setPower(fup1.getPower() * 1.2D);
            fup1.setUpTimes(fup1.getUpTimes() + 1);
            this.updateNotNull(fup1, request);
            this.delete(fup2.getId(), request);
        } else {
            fup2.setPower(fup2.getPower() * 1.2D);
            fup2.setUpTimes(fup2.getUpTimes() + 1);
            this.updateNotNull(fup2, request);
            this.delete(fup1.getId(), request);
        }
        return new JsonReturn(Constants.OK);
    }

    /**
     * 合成失败
     *
     * @param id      主键
     * @param request 请求
     * @return json返回值
     */
    private JsonReturn composeFailed(Long id, HttpServletRequest request) {
        this.delete(id, request);
        return new JsonReturn("合成失败");
    }

    /**
     * 根据球员主键和续约次数查找对应球员
     *
     * @param userId 用户主键
     * @param qyId   球员主键
     * @param xycs   续约次数
     * @return 对应球员
     */
    @Override
    public FootUserPerson findPersonByQyidandXycs(Long userId, Long qyId, Integer xycs) {
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != userId) {
            criteria.andEqualTo(Constants.USERID, userId);
        }
        criteria.andEqualTo("qyId", qyId);
        criteria.andEqualTo("xycs", xycs);
        criteria.andEqualTo("delFlag", 0);
        example.orderBy(SORT).desc();
        return this.findByExample(example);
    }

    /**
     * 天梯赛 获取符合条件的战队并随机取一个
     *
     * @param userSession 用户实体类
     * @return 符合条件的战队并随机取一个
     */
    @Override
    public FootTeam getRandomTeam(FootUser userSession) {
        List<FootUser> list = new ArrayList<>();
        List<FootUser> users = footUserService.getAllWithoutAdmin(null);
        if (users != null && !users.isEmpty()) {
            for (FootUser user : users) {
                //根据每个用户查看符合天梯赛条件
                if (this.checkMainPerson(user) >= 18 && !user.getNike().equals(userSession.getNike())) {
                    list.add(user);
                }
            }
        }
        if (!list.isEmpty()) {
            //随机取一个球队
            Random r = new Random();
            FootUser user = list.get(r.nextInt(list.size() - 1));
            return footTeamService.getTeamByUserid(user.getId());
        }
        return null;
    }

    /**
     * 根据球员信息查找是否有对应已经设为主力的队员
     *
     * @param userId 用户主键
     * @param fup    球员用户关系实体类
     * @return 是否设为主力的队员
     */
    @Override
    public boolean findPersonMain(Long userId, FootUserPerson fup) {
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != userId) {
            criteria.andEqualTo(Constants.USERID, userId);
        }
        criteria.andEqualTo("qyId", fup.getQyId());
        criteria.andEqualTo("delFlag", 0);
        example.orderBy(SORT).desc();
        List<FootUserPerson> list = this.findall(example);
        if (list != null && !list.isEmpty()) {
            for (FootUserPerson fups : list) {
                if (fups.getMain()) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 根据等级主键获取球员列表
     *
     * @param djId 等级主键
     * @return 球员列表
     */
    private List<FootPerson> findByDjId(Long djId) {
        return footPersonService.findByDjId(djId);
    }

    /**
     * 删除没有的球员
     *
     * @param qyId 球员主键
     */
    @Override
    public void deletePersonByQyid(Long qyId) {
        Example example = new Example(FootUserPerson.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("qyId", qyId);
        List<FootUserPerson> list = this.findall(example);
        if (list != null && !list.isEmpty()) {
            for (FootUserPerson fup : list) {
                this.delete(fup.getId(), null);
            }
        }
    }

    /**
     * 查找球队所有球员
     *
     * @param userId  用户主键
     * @param request 请求
     * @return 球员列表
     */
    @Override
    public List<FootPerson> findQd(FootBfinfo bf, boolean isQd1, HttpServletRequest request) {
        List<FootUserPerson> list;
        Map<String, Object> map = new HashMap<>();
        if (isQd1) {
            list = this.findPersonByUserId(bf.getQd1());
        } else {
            list = this.findPersonByUserId(bf.getQd2());
        }
        if (list == null || list.isEmpty()) {
            return Collections.emptyList();
        }
        List<FootPerson> personList = new ArrayList<>();
        for (FootUserPerson fup : list) {
            FootPerson fp = footPersonService.get(fup.getQyId());
            if (null != fp) {
                BeanUtils.copyProperties(fup, fp);
                fp.setFupId(fup.getId());
                fp.setJq(footBfDetailService.findByBfIdAndJqId(bf.getId(), fup.getId()));
                fp.setZg(footBfDetailService.findByBfIdAndZgId(bf.getId(), fup.getId()));
                fp.setMvp(footBfMvpService.findByBfIdAndMvpId(bf.getId(), fup.getId()));
                personList.add(fp);
            } else {
                if (fup.getQyId() != null) {
                    this.delete(fup, request);
                }
            }
        }
        personList.sort(Comparator.comparing(FootPerson::getDjId));
        return personList;
    }

}
